package com.atguigu.gmall.web.all.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;


@Controller //跳页面
public class SkuItemController {

    @Autowired
    SkuItemFeignClient skuItemFeignClient;

    @GetMapping("/{skuId}.html")
    public String getSkuInfo(@PathVariable("skuId") Long skuId,
                             Model model){

        //把当前sku的所有数据交给页面
        Result<Map<String,Object>> item = skuItemFeignClient.getItem(skuId);
        Map<String,Object> data = item.getData();

        //把远程调用得到的所有内容全部交给model, 放在页面的请求域中
        model.addAllAttributes(data);

        return "item/index";
    }
}
